// stores/userInfo.js
import { defineStore } from 'pinia'
import { computed, reactive } from 'vue'




export const useGoodsStore = defineStore('GoodsStoreNew', () => {

  //定义的数据
  let goods = reactive({
    name: '魔方法式软面包111111',
    price: 19.8,
    count: 1
  })


  //getters
  let amount = computed(() => {
    return Number((goods.count * goods.price).toFixed(2))
  })


  //方法  actions
  function plusCount() {
    goods.count++
  }
  function increament(num: number) {
    goods.count += num;
  }

  function subCount() {
    if (goods.count == 1) {
      return
    }
    goods.count--
  }




  return { goods, amount  ,plusCount,increament,subCount}



})